// 读取数据
val studentsDF = spark.read.jdbc(databaseUrl + "students", "students", connectionProperties)

// 删除特定ID的学生记录，这里通过筛选出除该ID之外的所有记录
val idToRemove = 10
val updatedDF = studentsDF.filter($"student_id" !== idToRemove)

// 为了安全起见，建议先备份原表
spark.sql(s"CREATE TABLE students_temp_backup AS SELECT * FROM students")

// 覆盖写回原表，实现删除效果
updatedDF.write
  .mode(SaveMode.Overwrite)
  .jdbc(databaseUrl + "students", "students", connectionProperties)

// 验证是否删除成功
// 读取更新后的表
val verifiedDF = spark.read.jdbc(databaseUrl + "students", "students", connectionProperties)
// 查询被删除ID的记录是否存在
val isDeleted = verifiedDF.filter($"student_id" === idToRemove).count() == 0

if(isDeleted) println("学生ID已被成功删除。") else println("删除失败，学生ID仍然存在。")